import React from 'react';
import CommonLoading from '@/components/CommonLoading';

//错误映射
const errorMap = [
	'Failed to fetch dynamically imported module',
	'Unable to preload CSS',
	'does not provide an export named',
]

//错误处理组件
export default class ErrorBoundary extends React.PureComponent {
	constructor(props) {
		super(props);
		this.state = { hasError: false, errorInfo: '' };
	}

	static getDerivedStateFromError(error) {
		const errStr = error.toString();
		if (errStr) {
			return { hasError: true, errorInfo: errStr };
		}
		return { hasError: true };
	}

	componentDidCatch(error, errorInfo) {
		console.log(error, errorInfo, 'error');
	}

	render() {
		if (this.state.hasError) {
			// You can render any custom fallback UI you want here
			return  <CommonLoading loading={true} />;
		}
		return this.props.children; // Render the child components
	}
}